/*
 * Author  : Leo <lipf160627@163.com>
 * Created : 2025-7-27
 * Desc    : Servo driver of PCA9685 which uses I2C protocol.
 */

#include "servo.hpp"

#include "driver/i2c_master.h"

Servo::Servo(gpio_num_t pinSCL, gpio_num_t pinSDA)
    : m_pinSCL(pinSCL), m_pinSDA(pinSDA)
{
    this->init();
}

Servo::~Servo()
{
}

void Servo::init()
{
    i2c_master_bus_config_t i2c_bus_config = {
        .i2c_port   = -1,
        .sda_io_num = m_pinSDA,
        .scl_io_num = m_pinSCL,
        .clk_source = I2C_CLK_SRC_DEFAULT,
        .glitch_ignore_cnt = 7,
    };
    i2c_master_bus_handle_t bus_handle;

    ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &bus_handle));
}
